<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MBTI测试 - 个性报告{$order_no}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="/css/report.css">
    <link rel="stylesheet" href="/css/results.css">
    <link rel="stylesheet" href="/css/all.min.css">
</head>
<body>
<!-- 密码保护遮罩 -->
<div class="password-overlay" id="password-overlay">
    <div class="password-wrapper">
        <div class="password-container" style="margin-top: 40px;">
            <p style="color: #666; margin-top: -5px; font-size: 20px; text-align: center;">报告编号: <span id="report-id">{$order_no}</span></p>
            <h2 style="margin-top: 10px;">MBTI个性报告</h2>

            <!-- 维度分析预览 -->
            <div class="dimension-preview" style="margin-top: 25px;">
                <h3>维度偏好分析</h3>

                <div class="dimension-item">
                    <div class="dimension-labels">
                        <span>内向 (I)</span>
                        <span>外向 (E)</span>
                    </div>
                    <div class="dimension-bar">
                        <div class="bar-fill" style="width: 63%"></div>
                        <span class="percentage">63%</span>
                    </div>
                </div>

                <div class="dimension-item">
                    <div class="dimension-labels">
                        <span>感觉 (S)</span>
                        <span>直觉 (N)</span>
                    </div>
                    <div class="dimension-bar">
                        <div class="bar-fill" style="width: 70%"></div>
                        <span class="percentage">70%</span>
                    </div>
                </div>

                <div class="dimension-blur"></div>
                <div class="dimension-lock" id="dimension-unlock">
                    <i class="fas fa-lock"></i> 解锁完整分析
                </div>
            </div>

            <!-- 报告维度标签 -->
            <p>您的完整报告包含以下13个维度的深入分析：</p>
            <div class="report-dimensions">
                <div class="dimension-tag"><i class="fas fa-chart-bar"></i> 维度偏好分析</div>
                <div class="dimension-tag"><i class="fas fa-user"></i> 性格类型概述</div>
                <div class="dimension-tag"><i class="fas fa-star"></i> 性格特点</div>
                <div class="dimension-tag"><i class="fas fa-briefcase"></i> 职业发展</div>
                <div class="dimension-tag"><i class="fas fa-users"></i> 人际关系</div>
                <div class="dimension-tag"><i class="fas fa-book"></i> 学习风格</div>
                <div class="dimension-tag"><i class="fas fa-heart-broken"></i> 情感管理</div>
                <div class="dimension-tag"><i class="fas fa-lightbulb"></i> 创造力与创新</div>
                <div class="dimension-tag"><i class="fas fa-crown"></i> 领导风格</div>
                <div class="dimension-tag"><i class="fas fa-hands-helping"></i> 团队合作</div>
                <div class="dimension-tag"><i class="fas fa-clock"></i> 时间管理</div>
                <div class="dimension-tag"><i class="fas fa-balance-scale"></i> 决策风格</div>
                <div class="dimension-tag"><i class="fas fa-seedling"></i> 个人成长</div>
                <div class="dimension-tag"><i class="fas fa-address-book"></i> 压力应对</div>
            </div>

            <div class="highlight-box">
                <h3 style="color: #ffffff; text-shadow: 0 1px 3px rgba(0,0,0,0.2);">解锁您的完整个性报告</h3>
                <div class="price-tag">
                    <div class="original-price">原价: <span>￥99</span></div>
                    <div class="current-price">限时特惠: <span>￥{$price}</span></div>
                    <div class="countdown">
                        <span>限时优惠倒计时</span>
                        <div class="timer">
                            <span id="minutes">15</span>分
                            <span id="seconds">00</span>秒
                        </div>
                    </div>
                </div>
                <p style="color: rgba(255, 255, 255, 0.9);">深入了解自己的性格维度偏好，发现您的独特优势，应对成长挑战，找到适合您的发展方向。</p>
                <button class="cta-button" id="focus-password">立即解锁报告</button>
                <div style="margin-top: 15px; font-size: 15px; color: rgba(255, 255, 255, 0.85);">
                    <i class="fas fa-users"></i> 已有 <strong style="font-size: 17px; color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.1);">12,847</strong> 人解锁此报告
                </div>
            </div>

            <div class="payment-section">
                <div class="payment-header">选择支付方式</div>
                <div class="payment-buttons">
                    <!-- 支付宝按钮 -->
                    <button class="payment-button alipay" data-type="alipay">
                        <div class="payment-icon">
                            <i class="fab fa-alipay"></i>
                        </div>
                        <div class="payment-info">
                            <span class="payment-name">支付宝支付</span>
                            <span class="payment-desc">推荐使用付款</span>
                        </div>
                    </button>

                    <!-- 微信支付按钮 -->
                    <button class="payment-button wechat" data-type="wechat">
                        <div class="payment-icon">
                            <i class="fab fa-weixin"></i>
                        </div>
                        <div class="payment-info">
                            <span class="payment-name">微信支付</span>
                            <span class="payment-desc">(H5端暂不支持)</span>
                        </div>
                    </button>
                </div>
                
                <!-- 确认支付按钮 -->
                <button class="payment-confirm" id="confirm-payment">
                    <i class="fas fa-check-circle"></i>
                    确认支付 ￥{$price}
                </button>
            </div>
        </div>
    </div>
</div>

<div class="container blurred-content" id="report-container">


    <div class="report-content">
        <!-- 报告内容保持不变 -->
        <!-- ... 原有报告内容 ... -->
    </div>

</div>
<script src="/js/jquery-3.5.1.min.js"></script>
<script src="/js/report.js"></script>
<script src="/js/sweetalert2.js"></script>
<script>
    // 密码验证功能
    $("#password-submit").click(function (){
        $.ajax({
            url: '/results',
            method: 'POST',
            data:{
                password:$("#report-password").val()
            },
            success: function(response) {
                if (response.code == 0) {
                    questions = response.data;  // 将数据赋值给全局变量
                    Swal.fire({
                        allowEscapeKey: false, // 禁止ESC键关闭弹窗
                        allowEnterKey: false, // 禁止回车键关闭弹窗
                        showCloseButton: false, // 隐藏关闭按钮
                        text: '请勿关闭页面,正在生成报告,请耐心等待!',
                        icon: 'success',
                        timer: 5000, // 弹窗显示3秒
                        showConfirmButton: false, // 不显示确认按钮
                        allowOutsideClick: false, // 禁止点击弹窗外部关闭弹窗
                        didOpen: () => {
                            Swal.showLoading(); // 显示加载动画
                        },
                        willClose: () => {
                            return false; // 阻止弹窗关闭
                        }
                    }).then(() => {
                        // 2秒后进行页面跳转
                        window.location.href = `/report?order_no=${questions.order_no}&secret=${questions.password}`;
                    });
                } else {
                    Swal.fire({
                        text: response.msg,
                        timer: 1000,
                        icon: 'error',
                        customClass: {
                            popup: 'custom-swal'
                        },
                        height: 222,
                        width: 222
                    });
                }
            },
            error: function(error) {
                console.log("请求出错:", error);
            }
        });
    });

    // 通用函数：滚动到密码输入框并聚焦
    function scrollToPasswordInput() {
        const passwordInput = document.getElementById('report-password');
        const passwordForm = document.querySelector('.password-form');

        // 平滑滚动到密码输入框位置
        passwordForm.scrollIntoView({ behavior: 'smooth', block: 'center' });

        // 短暂延迟后聚焦，确保滚动完成
        setTimeout(() => {
            passwordInput.focus();

            // 添加闪烁效果提示用户
            passwordInput.classList.add('input-highlight');
            setTimeout(() => {
                passwordInput.classList.remove('input-highlight');
            }, 1000);
        }, 500);
    }

    // 为"立即解锁报告"按钮添加事件监听器
    document.getElementById('focus-password').addEventListener('click', scrollToPasswordInput);

    // 为"解锁查看完整分析"按钮添加事件监听器
    document.getElementById('dimension-unlock').addEventListener('click', scrollToPasswordInput);

    // 添加维度条动画
    document.addEventListener('DOMContentLoaded', function() {
        setTimeout(() => {
            const barFills = document.querySelectorAll('.bar-fill');
            barFills.forEach(bar => {
                const width = bar.style.width;
                bar.style.width = '0';
                setTimeout(() => {
                    bar.style.width = width;
                }, 200);
            });
        }, 500);
    });

    // 支付方式选择和确认
    let selectedPayment = null;
    const confirmBtn = document.getElementById('confirm-payment');

    // 支付按钮点击处理
    document.querySelectorAll('.payment-button').forEach(button => {
        button.addEventListener('click', function() {
            // 移除其他按钮的active状态
            document.querySelectorAll('.payment-button').forEach(btn => {
                btn.classList.remove('active');
            });
            // 添加当前按钮的active状态
            this.classList.add('active');
            
            // 记录选中的支付方式
            selectedPayment = this.dataset.type;
            
            // 激活确认按钮
            confirmBtn.classList.add('active');
        });
    });

    // 确认支付按钮点击处理
    confirmBtn.addEventListener('click', function() {
        if (!selectedPayment) return;
        
        if (selectedPayment === 'alipay') {
            // 显示加载中
            Swal.fire({
                title: '正在跳转支付宝支付',
                text: '请稍候...',
                allowOutsideClick: false,
                showConfirmButton: false,
                didOpen: () => {
                    Swal.showLoading();
                }
            });
            window.location = "/v1/pay?pay_type=0&order_no={$order_no}&pay_type=alipay&order_type=0";
        } else if (selectedPayment === 'wechat') {
            // 创建微信支付订单
            $.ajax({
                url: '/v1/pay?pay_type=0&order_no={$order_no}&pay_type=wx&order_type=0',
                method: 'GET',
                success: function(response) {
                    if(response.code === 0) {
                        showWechatPayModal(response);
                    } else {
                        Swal.fire({
                            icon: 'error',
                            title: '创建订单失败',
                            text: response.msg || '请稍后重试'
                        });
                    }
                }
            });
        }
    });

    // 显示微信支付二维码弹窗
    function showWechatPayModal(response) {
        const modalHtml = `
            <div class="wechat-pay-modal">
                <div class="qrcode-amount">￥${response.data.amount}</div>
                <div class="qrcode-container">
                    <img src="${response.data.qrcode}"
                         alt="微信支付二维码"
                         style="width:400px; height:400px; display:block; margin:0 auto;">
                </div>
                <div class="pay-tips">
                    <div class="tips-icon">
                        <i class="fas fa-info-circle"></i>
                    </div>
                    <div class="tips-text">
                        <p>请使用微信扫码支付</p>
                        <p class="warning">请勿关闭窗口，支付完成后将自动生成报告</p>
                    </div>
                </div>
            </div>
        `;
        
        Swal.fire({
            title: '微信支付',
            html: modalHtml,
            showConfirmButton: false,
            showCloseButton: true,
            customClass: {
                popup: 'wechat-pay-popup'
            },
            didOpen: () => {
                checkPayStatus(response.data.order_no);
            }
        });
    }

    // 检查支付状态
    function checkPayStatus(orderNo) {
        // 清除可能存在的旧定时器
        if (window.payCheckTimer) {
            clearInterval(window.payCheckTimer);
        }

        window.payCheckTimer = setInterval(() => {
            $.ajax({
                url: '/api/check_pay_status',
                method: 'POST',
                data: { order_no: orderNo },
                success: function(response) {
                    if (response.data.return_msg == "OK" && response.data.return_code == "SUCCESS" && response.data.trade_state_desc != "订单未支付") {
                        clearInterval(window.payCheckTimer);
                        Swal.fire({
                            icon: 'success',
                            title: '支付成功',
                            text: '正在生成报告...',
                            showConfirmButton: false,
                            timer: 2000
                        }).then(() => {
                            window.location.href = `/alipay/return?out_trade_no=${response.data.out_trade_no}`;
                        });
                    }
                }
            });
        }, 3000);
    }

    // 添加倒计时功能
    function startCountdown() {
        let minutes = 15;
        let seconds = 0;
        const minutesDisplay = document.getElementById('minutes');
        const secondsDisplay = document.getElementById('seconds');

        const timer = setInterval(() => {
            if (seconds === 0) {
                if (minutes === 0) {
                    clearInterval(timer);
                    // 时间到后的处理
                    Swal.fire({
                        title: '优惠时间已结束',
                        text: '抱歉，您错过了优惠价格',
                        icon: 'warning',
                        confirmButtonText: '确定'
                    }).then(() => {
                        // 可以选择刷新页面或更新价格
                        location.reload();
                    });
                    return;
                }
                minutes--;
                seconds = 59;
            } else {
                seconds--;
            }

            // 更新显示
            minutesDisplay.textContent = minutes.toString().padStart(2, '0');
            secondsDisplay.textContent = seconds.toString().padStart(2, '0');

            // 当剩余时间少于5分钟时添加紧急效果
            if (minutes < 5) {
                document.querySelector('.countdown').classList.add('urgent');
            }
        }, 1000);
    }

    // 页面加载时启动倒计时
    document.addEventListener('DOMContentLoaded', function() {
        startCountdown();
    });

    // 添加以下JavaScript代码来修复解锁按钮功能

    document.addEventListener('DOMContentLoaded', function() {
        // 获取两个解锁按钮
        const unlockReportBtn = document.getElementById('focus-password');
        const dimensionUnlockBtn = document.getElementById('dimension-unlock');
        
        // 定义解锁功能函数
        function handleUnlockClick() {
            // 滚动到支付区域
            const paymentSection = document.querySelector('.payment-section');
            if (paymentSection) {
                paymentSection.scrollIntoView({ behavior: 'smooth', block: 'center' });
                
                // 添加高亮效果
                paymentSection.classList.add('highlight-section');
                setTimeout(() => {
                    paymentSection.classList.remove('highlight-section');
                }, 1500);
                
                // 自动选中第一个支付方式
                const firstPaymentBtn = document.querySelector('.payment-button');
                if (firstPaymentBtn) {
                    firstPaymentBtn.click();
                }
            }
        }
        
        // 为两个按钮添加点击事件
        if (unlockReportBtn) {
            unlockReportBtn.addEventListener('click', handleUnlockClick);
        }
        
        if (dimensionUnlockBtn) {
            dimensionUnlockBtn.addEventListener('click', handleUnlockClick);
        }
    });

</script>
</body>
</html>